//
//  NSString+Extension.m
//  XinLang_OC
//
//  Created by WONG on 16/4/2.
//  Copyright © 2016年 cheuhui. All rights reserved.
//

#import "NSString+Extension.h"

@implementation NSString (Extension)

- (NSString *)sinaSource {
    //<a href="http://app.weibo.com/t/feed/2cEJdS" rel="nofollow">IT之家</a>
    NSString *pattern = @">(.*?)<";
    
    NSError *error = nil;
    
    NSRegularExpression *rge = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:&error];
    
    //    NSAssert(error == nil, @"正则表达式创建失败：%@",error);
    if (error) {
        NSLog(@"正则表达式创建失败：%@",error);
    }
    
    NSArray *result = [rge matchesInString:self options:0 range:NSMakeRange(0, self.length)];
    
    NSUInteger count = result.count;
    
    if (count == 0) {
        // 没有来源
        return @"未知来源";
    } else {
        
        NSTextCheckingResult *rs = result.firstObject;
        
        NSRange range = NSMakeRange(rs.range.location + 1, rs.range.length - 2);
        
        // 截起子字符串
        NSString *text = [self substringWithRange:range];
        return text;
    }
    
}










@end
